<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单商品</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容">
            <el-button icon="el-icon-search" slot="append"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 订单列表 -->
      <el-table :data="orderList" border style="width: 100%" create_time>
        <el-table-column prop="order_number" label="订单编号" width="120px"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">{{scope.row.create_time|dataFormate}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" icon="el-icon-edit" @click="showEditAddress()"></el-button>
            <el-button
              size="mini"
              type="success"
              icon="el-icon-location"
              @click="showAddresTime(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <!-- 修改地址的对话框 -->
      <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" @close="addressDialogClosed">
        <!-- form表单 -->
        <el-form
          :model="addressForm"
          :rules="addressFormRules"
          ref="addressFormRef"
          label-width="80px"
        >
          <el-form-item label="省市区县" prop="address1">
            <el-cascader :options="cityData" v-model="addressForm.address1"></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="addressForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="editAddress">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 显示地址时间线 -->
      <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :timestamp="activity.ftime"
          >{{activity.context}}</el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
import cityData from './citydata.js'
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      //总页数
      total: 0,
      //订单列表
      orderList: [],
      //修改地址对话框
      dialogVisible: false,
      //修改收货地址的表单
      addressForm: {
        address1: [],
        address2: ''
      },
      addressFormRules: {
        address1: [
          { required: true, message: '请选择省市区县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      cityData,
      //时间线弹框
      progressVisible: false,
      //物流信息的地址和实践
      activities: []
      //   context: '',
      //   ftime: ''
    }
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      console.log(res)

      this.orderList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange(newSize) {
      //   console.log(newSize)
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange(newCurrent) {
      //   console.log(newCurrent)
      this.queryInfo.pagenum = newCurrent
      this.getOrderList()
    },
    showEditAddress(res) {
      //当用户点击修改收货地址按钮时触发
      this.dialogVisible = true
      console.log(res)
    },
    //弹框关闭清除数据
    addressDialogClosed() {
      this.$refs.addressFormRef.resetFields()
    },
    //提交表单
    editAddress() {},
    //显示地址
    async showAddresTime(row) {
      //   console.log(row)
      this.progressVisible = true
      //发请求
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      if (res.meta.status != 200) {
        return this.$message.erros('修改地址失败')
      }

      //物流地址
      this.activities = res.data
      //   this.context = res.data.context
      //   this.ftime = res.data.ftime
    }
  },
  created() {
    this.getOrderList()
  }
}
</script>
<style lang="less" scoped>
</style>